package com.ax.base.drugadministration.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ax.base.common.utils.PageUtils;
import com.ax.base.common.utils.Query;
import com.ax.base.drugadministration.dao.BaseDrugManagerMapper;
import com.ax.base.drugadministration.domain.BaseDrugManager;
import com.ax.base.drugadministration.service.DrugAdministrationManagerService;

@Service("DrugAdministrationManagerService")
public class DrugAdministrationManagerServiceImpl implements DrugAdministrationManagerService {
    
	@Autowired
	BaseDrugManagerMapper baseDrugManagerMapper;
	/**
	 * 药监查询(模块:药监人员)
	 * 
	 * @param Map<String, Object> map
	 *           
	 * @return PageUtils
	 */
	@Override
	public List<BaseDrugManager> queryDrugAdministrationManagerSer(Map<String, Object> params) {
	//	Query query = new Query(params);
		List<BaseDrugManager> baseDrugManagers = baseDrugManagerMapper.queryDrugAdministrationManagerMapper(params);
	//	int total = baseDrugManagerMapper.count(query);
	//	PageUtils pageUtil = new PageUtils(baseDrugManagers,total);
		return baseDrugManagers;
	}
	
	/**
	 * 药监保存(模块:药监人员)
	 * 
	 * @param BaseDrugManager baseDrugManager
	 *           
	 * @return SUCC
	 */
	@Override
	public void insertDrugManagerSer(BaseDrugManager baseDrugManager) {
		baseDrugManagerMapper.insertSelective(baseDrugManager);
		
	}
	
	/**
	 * 药监修改(模块:药监人员)*跳转修改页面
	 * 
	 * @param Long id
	 *           
	 * @return HTML
	 */
	@Override
	public BaseDrugManager getBaseDrugManagerSer(Long id) {
		BaseDrugManager baseDrugManager = baseDrugManagerMapper.selectByPrimaryKey(id);
		return baseDrugManager;
	}

	/**
	 * 药监修改(模块:药监人员)
	 * 
	 * @param BaseDrugManager baseDrugManager
	 *           
	 * @return SUCC
	 */
	@Override
	public void updateDrugManagerSer(BaseDrugManager baseDrugManager) {
		baseDrugManagerMapper.updateByPrimaryKeySelective(baseDrugManager);
	}

	/**
	 * 药监修改状态(模块:药监人员)
	 * 
	 * @param drugManagerId,flag
	 *           
	 * @return SUCC
	 */
	@Override
	public void updateStateSer(BaseDrugManager baseDrugManager) {
		baseDrugManagerMapper.updateByPrimaryKeySelective(baseDrugManager);
	}

	/**
	 * 编号是否重复(新增)
	 * 
	 * @param Map<String, Object> map
	 *         
	 * @return boolean
	 */
	@Override
	public boolean validateSer(Map<String, Object> params) {
		boolean validate;
		validate = baseDrugManagerMapper.validateMapper(params).size() > 0;
		return validate;
	}
	/**
	 * 是否重复(修改)
	 * 
	 * @param String parameter
	 *         
	 * @return boolean
	 */
	@Override
	public boolean updateValidateSer(String pt) {
		Map<String,Object> params = new HashMap<String,Object>(); 
		String[] pts = pt.split(",");
		String pd = pts[2];
		params.put("drugManagerId",pts[1]);
		if(pd.equals("empno")){
		params.put("empno",pts[0]);
		}else if(pd.equals("phone")){
		params.put("phone",pts[0]);
		params.put("empno",null);
		}else{
		params.put("personId",pts[0]);
		params.put("empno",null);
		}
		boolean validate;
		validate = baseDrugManagerMapper.updatevalidateMapper(params).size() > 0;
		return validate;
	}

}
